﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace DAL
{
    public partial class Accounts
    {
        internal static long? GetLastPostID(int accountID)
        {
            string cmd = @"
Select Max(cast( ForeignID as BigInt)) from Posts
Where AccountID = @accountID";

            var val = DBHelper.GetScalar(cmd, new SqlParameter("accountID", accountID));
            if (val == DBNull.Value)
                return null;

            return Convert.ToInt64(val);
        }

        internal static DataRow GetLastPost(int pageID)
        {
            string cmd = @"Select Top 1 * from Posts
	                        Where PageID = @pageID
	                        Order By DATE Desc";

            var tbl = DBHelper.GetTable(cmd, new SqlParameter("pageID", pageID));

            if (tbl != null && tbl.Rows.Count > 0)
                return tbl.Rows[0];
            return null;
        }
    }
}
